﻿@using CoralNode.Core.Entity.Domains.Prototype
@model IList<ProtoypeFieldCustomDomain>
@Html.IncludePage("CoralAdmin/prototype", "_Left", new { current = "prototype" })
@{
    var prototypeId = long.Parse(Request.QueryString["prototypeId"]);
    ViewData["curr"] = "fieldCustom";
    List<PrototypeFieldDomain> filedList = ((IList<PrototypeFieldDomain>)ViewBag.FieldList).ToList();
    foreach (var field in filedList) {
        field.FieldName = string.Format("Field.{0}", field.FieldName);
    }
    filedList.Add(new PrototypeFieldDomain { FieldName = "Id", Title = "编号",Rank = -2});
    filedList.Add(new PrototypeFieldDomain { FieldName = "Title", Title = "标题",Rank = -1});
    filedList = filedList.OrderBy(n => n.Rank).ToList();
    if (Model.Count > 0)
    {
        filedList = filedList.Where(n => Model.FirstOrDefault(f=>f.FieldName==n.FieldName)==null).ToList();
    }
}
<div id="pbody">
    <div class="extra">
        <div class="pbody_top">
            <span class="ico ico_setting_system"></span><span class="t t_c">内容设计&nbsp;&nbsp;/&nbsp;&nbsp;<b
                class=" t_small f_no">原型管理</b></span>
        </div>
        <div id="main">
            @Html.IncludePage("CoralAdmin/Prototype", "_tab", new { prototypeId = prototypeId })
            <div class="">
                <div class="tablelist_style1" data-js="tabellist_style1">
                    <div class="funsearch p_1 pl_2 pr_2 extra_normal">
                        <a class="btn_5 f_r ml_3 j_add_fieldList" href="#">添加字段</a>

                    </div> 
                    <table class="j_custom_field" cellpadding="0" cellspacing="0">
                        <tr class="exclude">
                            <th width="60">名称</th>
                            <th>排序</th>
                            <th width="140">操作</th>
                        </tr>
                        @foreach (var item in Model)
                        {
                            <tr data-depth="0">
                                <td>@item.Title</td>
                                  <td><a href="/m/prototype/ChangeFieldCustomRank/@item.Id" class="ico ico_moveup mr_2 f_no  btn"></a><a href="/m/prototype/ChangeFieldCustomRank/@item.Id" class="ico ico_movedown btn"></a>
                                </td>
                                <td>
                                    <div class="fun">
                                    <a href="/m/prototype/deleteFieldCustom/@item.Id" class="js_delete">删除</a>
                                        </div>
                                </td>
                            </tr>
                        }
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>
<div style="display: none">
    <div class="add_field_custom">
         <div id="upload_d">
        <div class="upload_d_t">
            选择字段
        </div>
        <div class="cutbox clearfix">
            <div class=" form_main  table_form ">
                <table>
                    @foreach (var item in filedList)
                {
                    <tr>
                        <td>
                            <label class="checkbox_own">
                                <input type="checkbox" value="@item.FieldName" fieldType="@item.FieldType"></label></td>
                        <td>@item.Title</td>
                    </tr>
                }
            </table>
                
            </div>
        </div>
        <div class="opbtnbox clearfix">
            <span class="btn btn_green_normal w_8 okbtn">确定</span><span class="btn pl_2 cancelbtn">取消</span>
        </div>
    </div>
       </div>
</div>
<script>
    $(document).ready(function () {
        $('.j_add_fieldList').click(function () {
            var cutDialog = $.dialog({
                title: '',
                content: '<img src="/Themes/CoralAdmin/_misc/images/loading.gif" style="display:block; margin:30px auto;" />',
                background: "#000",
                opacity: 0.4,
                lock: true,
                paddding: "0"
            });
            $('body').css("overflow", "auto");
            cutDialog.content($('.add_field_custom').html());
            $('.okbtn').live("click", function () {
                var $check = cutDialog.getJQuery().find('.checkbox_own');
                var field = new Array();
                $check.each(function(i, n) {
                    if ($(n).hasClass('selected')) {
                        field.push('{"FiledName":"' + $(n).find("input").val() + '","Title":"' + $(n).parent().next().text() + '","FieldType":"' + $(n).find("input").attr("fieldType")+ '"}');
                    }
                });
                if (field.length > 0) {
                    $.post("/m/prototype/savefieldcustom", { fieldjson: "[" + field + "]", prototypeid: "@prototypeId" }, function(c) {
                        if (c.length>0) {
                            location.reload();
                        }
                    });
                } else {
                    alert("请选择");
                }
            });
            $('.cancelbtn').live("click", function () {
                cutDialog.close();
            });
        });
    });
</script>
